package 并发编程16.实际运用场景;

import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.DelayQueue;

/**
 * @author idea
 * @data 2019/2/10
 */
public class Demo {

    public static void main(String[] args) throws InterruptedException {
        int studentNumber=20;
        CountDownLatch countDownLatch=new CountDownLatch(studentNumber+1);
        DelayQueue<Student> students=new DelayQueue<Student>();
        Random random=new Random();
        for(int i=0;i<studentNumber;i++){
            students.put(new Student("student"+i,30+random.nextInt(120),countDownLatch));
        }
        Thread teacherThread=new Thread(new Teacher(students));
        students.put(new EndExam(students,(int)120,countDownLatch,teacherThread));
        teacherThread.start();
        countDownLatch.await();
        System.out.println("考试时间到");
    }
}
